#!/bin/bash
./gradlew clean liveness:assembleRelease ocr:assembleRelease

version=$1

if [[ ${version} == "" ]]; then
	version=`date '+%Y-%m-%d'`
fi

originIdentityPath="./ocr/build/outputs/aar/moxie-ocr*"
originLivenessPath="./liveness/build/outputs/aar/moxie-liveness*"
sdkPath="./sdk/"
libsPath="./MXSample/libs/"
outputPath="./output/"

if [[ ! -d ${sdkPath} ]]; then
    mkdir ${sdkPath}
fi

cp ${originIdentityPath} ${sdkPath}
cp ${originLivenessPath} ${sdkPath}

rm ${libsPath}com.moxie.*
cp -r ${sdkPath}* ${libsPath}

if [[ ! -d ${outputPath} ]]; then
    mkdir ${outputPath}
fi

zipName="MoxieFaceSDK_Android-$version.zip"

cp ./MXSample/build-types/release/dep.gradle ./MXSample/
cp ./MXSample/build-types/release/settings.gradle ./

zip -r ${zipName} ./MXSample ./sdk ./gradle ./.gitignore ./build.gradle ./gradlew ./gradlew.bat ./settings.gradle ./README.md ./license ./SDK ./使用文档 -x "./MXSample/build/*" -x "./MXSample/build-types/*" -x "./build/*" -x "*.iml"

if [[ ! -e ${zipName} ]]; then
    echo "打包失败"
else
    mv ${zipName} ${outputPath}
    echo "打包成功"
fi

cp ./MXSample/build-types/debug/dep.gradle ./MXSample/
cp ./MXSample/build-types/debug/settings.gradle ./
rm -rf ${sdkPath}